/*
* File :
* Created : 17 janv. 07
* By : eSpider Team
* Version : $Revision$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details ( see the LICENSE file ).
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package org.fbmc.file;

import java.io.File;

import entagged.audioformats.AudioFile;
import entagged.audioformats.AudioFileIO;

public class MusicFile extends MediaFile {
	
	private String artist;
	private String album;
	private String title;
	
	public MusicFile(){
		artist = "";
		album = "";
		title = "";
	}

	public MusicFile(File file) {
		super(file);
		
		try{
			AudioFile audioFile = AudioFileIO.read(file);
			
			System.out.println(file.getAbsolutePath());
			
			artist = (audioFile.getTag().getArtist().size() > 0)?audioFile.getTag().getArtist().get(0).toString():"";
			album = (audioFile.getTag().getAlbum().size() > 0)?audioFile.getTag().getAlbum().get(0).toString():"";
			title = (audioFile.getTag().getTitle().size() > 0)?audioFile.getTag().getTitle().get(0).toString():"";			
		}catch (Exception e) {
			artist = "";
			album = "";
			title = "";
		}
	}
		
	public Type getType() {
		return MediaFile.Type.music;
	}

	public String getAlbum() {
		return album;
	}

	public void setAlbum(String album) {
		this.album = album;
	}

	public String getArtist() {
		return artist;
	}

	public void setArtist(String artist) {
		this.artist = artist;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public int compareTo(MediaFile mediaFile) {
		if(super.compareTo(mediaFile) == 0){
			MusicFile file = (MusicFile)mediaFile;
			
			if(!this.artist.equals(file.getArtist())) return -1;
			if(!this.album.equals(file.getAlbum())) return -1;
			if(!this.title.equals(file.getTitle())) return -1;
					
		}		
		return 0;
	}
}
 